package com.example.config.initializer;
import com.example.config.common.Constants;
import com.example.config.properties.RemoteProperties;
import org.springframework.context.*;
import org.springframework.core.env.*;
import java.util.Map;

/**
 * @author <a href="juntao.zhang@bkjk.com">juntao.zhang</a>
 * @Description:
 * @Package com.example.config
 * @date 2017/12/13 17:28
 * @see
 */

public class CustomizableEnvironmentInitializer implements ApplicationContextInitializer {

    private static ConfigurableEnvironment env;

    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
        CustomizableEnvironmentInitializer.env = applicationContext.getEnvironment();
        MutablePropertySources mutablePropertySources = env.getPropertySources();
        PropertySource propertySource = new MapPropertySource("remote-config", Constants.remotePropertiesResource);
        mutablePropertySources.addFirst(propertySource);
    }
}
